
import grails.test.*

class DBStructureTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()

        // Populate type tables that are used in this test.
        // These will only be needed when testing with the in-memory DB.

        populateType(AddressType.class)
        assert 3 == AddressType.count()
        populateType(CompanyType.class)
        assert 3 == CompanyType.count()
        populateType(EmailType.class)
        assert 3 == EmailType.count()
        populateType(PhoneType.class)
        assert 3 == PhoneType.count()

        def state = State.findByName("Indiana")
        state.save()
        assert 1 == State.count()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testSomething() {
        // Test Uniqueness.
        type = new CompanyType(name:"Type1", description:"Description for type 1.")
        assert 0 == type.errors.getErrorCount()
        type.save();
        assert 1 == type.errors.getErrorCount()
        assert 3 == CompanyType.count()

        // Create Company
        def company = new Company(type:CompanyType.findById(1), name:"Company 1")
        company.save()

        phone = new Phone(type:PhoneType.findById(2), number:"618-483-3403")
        company.addToPhones(phone)

        println company

    }

    void populateType(Class clazz) {
        def type = clazz.newInstance(name:"Type1", description:"Description 1.");
        type.save()
        type = clazz.newInstance(name:"Type2", description:"Description 2.");
        type.save()
        type = clazz.newInstance(name:"Type3", description:"Description 3.");
        type.save()
    }

    void createCompany() {
        company.save()
    }
}


//        def title = new Title(name:"DDS", description:"DDS")
//        title.save()
//        title = new Title(name:"none", description:"None")
//        title.save()
//
//        def c = new Customer(title:Title.findByName("DDS"), firstName:"Dru", middleName:"D", lastName:"Devore")
//        c.save()
//        println c.id
//        def custs = Customer.findAll()
//        println "Printing the list 1"
//        custs.each{println it}
//        println "done."
//        c.setFirstName("Tami")
//
//        println "1"
//        def cust = new Customer()
//        println cust
//        println c.errors
//        cust.setFirstName("Dru")
//        cust.setMiddleName("test")
//        cust.setLastName("Devore2")
//        cust.setTitle(Title.findById(2))
//        cust.save()
//        println cust
//        println cust.id
//        def custs2 = Customer.findAll()
//        println "Printing the list 2"
//        custs2.each{println it}
//        println "done."
//
//        custs = Customer.findAll()
//        println "Printing the list a"
//        custs.each{println it}
//        println "done."
//        custs = Customer.findAll()
//        println "Printing the list b"
//        custs.each{println it}
//        println "done."
//        custs = Customer.findAll()
//        println "Printing the list c"
//        custs.each{println it}
//        println "done."
//        custs = Customer.findAll()
//        println "Printing the list d"
//        custs.each{println it}
//        println "done."
//
//
//        println "Customers name = $cust"
////        assertToString(doc, "NA Dru Devore2")
//        cust.setTitle(new Title(name:"Wizard", description:"The Wizard!").save())
//        cust.save()
//        custs = Customer.findAll()
//        println "Printing the list 3"
//        custs.each{println it}
//        println "done."
//
//        println "Customers name = " + cust
//        assertToString(cust, "Wizard Dru D Devore2")
//        Office office = new Office(name: "Dru's Office")
//        office.addToCustomers(cust)
//        println office.Customers.size()
